package cn.yunyichina.provider.base.service.impl;

import cn.yunyichina.provider.base.dao.ParamdetailDao;
import cn.yunyichina.provider.base.dao.ParamstructDao;
import cn.yunyichina.provider.base.entity.Paramdetail;
import cn.yunyichina.provider.base.entity.Paramstruct;
import cn.yunyichina.provider.framework.common.PKGenerator;
import cn.yunyichina.provider.iface.entity.common.ResponseObject;
import cn.yunyichina.utils.convert.JsonUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 接口结构详情服务实现
 */
@Service
public class ParamdetailServiceImpl {

    @Autowired
    private ParamdetailDao dao;

    public ResponseObject listParamdetail(String data) {
        Paramdetail wheres = null ;
        if(StringUtils.isNotBlank(data)) {
            wheres = JsonUtils.parseObject(data, Paramdetail.class);
        }

        ResponseObject response = new ResponseObject();
        response.setResultCodeAndMessage("0", "调用成功");
        List<Paramdetail> list = dao.select(wheres);
        response.setResultObject(list);
        return response;
    }

    public ResponseObject AddParamdetail(String data) {
        Paramdetail api= JsonUtils.parseObject(data, Paramdetail.class);
        api.setId(PKGenerator.generateId());
//        api.setCreatedTime(DateUtils.dateToString(new Date()));
        ResponseObject response = new ResponseObject();
        response.setResultCodeAndMessage("0", "保存成功");
        dao.insert(api);
        return response;
    }

    public ResponseObject updateParamdetail(String data) {
        Paramdetail api = JsonUtils.parseObject(data, Paramdetail.class);
        ResponseObject response = new ResponseObject();
        if(StringUtils.isBlank(api.getId())){
            response.setResultCodeAndMessage("1001", "更新id参数不能为空");
            return response;
        }
        response.setResultCodeAndMessage("0", "更新成功");
        dao.update(api);
        return response;
    }

    public ResponseObject deleteParamdetail(String data) {
        Paramdetail api = JsonUtils.parseObject(data, Paramdetail.class);
        ResponseObject response = new ResponseObject();
        if(StringUtils.isBlank(api.getId())){
            response.setResultCodeAndMessage("1001", "删除id参数不能为空");
            return response;
        }
        response.setResultCodeAndMessage("0", "删除成功");
        dao.delete(api);
        return response;
    }
}
